local dx_queue = require("dx_queue")
local config = require("config")
local dx_json = require("dx_json")

local start_service = {}

function start_service.running_status(ret)
    local status = config.get("run_status")
    local topic = "20220316/event/alarm" .. "####"
    local data = {}
    -- 启动状态（0：重置，1：正常，2：升级，3：看门狗）
    if not ret then
        if status == 0 then
            -- 重置重启，无需操作
        elseif status == 1 then
            -- 正常启动，无需操作
        elseif status == 2 then
            -- 升级启动，上送升级成功状态
            data["type"] = "5"
            data["value"] = "1"
            local req_mqtt = {topic = topic, data = data}
            dx_queue.push(mqtt_queue, dx_json.encode(req_mqtt), 500)
        elseif status == 3 then
            -- 看门狗重启，上送预警状态
            data["type"] = "6"
            data["value"] = "1"
            local req_mqtt = {topic = topic, data = data}
            dx_queue.push(mqtt_queue, dx_json.encode(req_mqtt), 500)
        end
    end
    -- 默认值为看门狗重启
    config.set("run_status","3")
end

return start_service
